package com.taxshare.seller.controller;

import com.taxshare.mybatis.pager.PageRequest;
import com.taxshare.pvalidate.ParamValid;
import com.taxshare.response.beans.Response;
import com.taxshare.seller.service.BlankInvoiceCollctionService;
import com.taxshare.seller.service.BlankInvoiceWarningService;
import com.taxshare.seller.service.StockDetailService;
import com.taxshare.seller.view.dto.BlankInvoiceCollctionDTO;
import com.taxshare.seller.view.dto.SetUpEarlyWarningDTO;
import com.taxshare.seller.view.dto.StockDetailDTO;
import com.taxshare.seller.view.vo.SellerInvoiceVO;
import com.taxshare.seller.view.vo.StockDetailVO;
import com.taxshare.seller.view.vo.SyncBlankInvoiceDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/blankInvoiceCollection")
@Api(tags = "空白发票管理")
public class BlankInvoiceCollctionController {

    @Autowired
    BlankInvoiceCollctionService blankInvoiceCollctionService;

    @Autowired
    BlankInvoiceWarningService blankInvoiceWarningService;

    @Autowired
    StockDetailService stockDetailService;

    @ParamValid
    @PostMapping("/setUpEarlyWarning")
    @ApiOperation(value = "设置预警值", notes = "发票库存管理")
    public Response setUpEarlyWarning(@RequestBody @Valid SetUpEarlyWarningDTO setUpEarlyWarningDTO) {
        return blankInvoiceWarningService.setUpEarlyWarning(setUpEarlyWarningDTO);
    }

    @PostMapping("/queryStockWarning")
    @ApiOperation(value = "余票预警提示", notes = "余票预警提示")
    public Response queryStockWarning(@RequestBody @Valid SetUpEarlyWarningDTO setUpEarlyWarningDTO) {
        return blankInvoiceWarningService.queryStockWarning(setUpEarlyWarningDTO);
    }

    @ParamValid
    @PostMapping("/selectWarningLog")
    @ApiOperation(value = "预警设置记录", notes = "发票库存管理")
    public Response selectWarningLog(@RequestBody SetUpEarlyWarningDTO setUpEarlyWarningDTO) {
        return blankInvoiceWarningService.selectWarningLog(setUpEarlyWarningDTO);
    }

    @PostMapping("/blankInvoiceCancel")
    @ApiOperation(value = "空白发票作废", notes = "空白发票作废")
    public Response blankInvoiceCancel(@RequestBody SellerInvoiceVO sellerInvoiceVO) throws Exception {
        return blankInvoiceCollctionService.blankInvoiceCancel(sellerInvoiceVO);
    }

    @PostMapping("/syncStockDetail")
    @ApiOperation(value = "库存明细同步", notes = "发票领购查询")
    public Response syncStockDetail(@RequestBody SyncBlankInvoiceDTO syncBlankInvoiceDTO) {
        return stockDetailService.syncStockDetail(syncBlankInvoiceDTO);
    }

    @PostMapping("/queryStockDetail")
    @ApiOperation(value = "发票领购查询", notes = "发票领购查询")
    public Response<StockDetailVO> queryStockDetail(@RequestBody PageRequest<StockDetailDTO> query) {
        return stockDetailService.queryStockDetail(query);
    }

    @PostMapping("/queryRemainderDetail")
    @ApiOperation(value = "库存管理查询", notes = "发票领购查询")
    public Response<StockDetailVO> queryRemainderDetail(@RequestBody PageRequest<StockDetailDTO> query) {
        return stockDetailService.queryRemainderDetail(query);
    }

}
